package com.tskj.mh.badminton.dao;

import com.alibaba.fastjson.JSONObject;
import com.tskj.mh.badminton.dao.mysql.DbUtilitys;
import com.tskj.mh.badminton.utility.Tools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Component
public class StudentDAO {

    @Autowired
    private DbUtilitys dbUtilitys;

    public boolean exists(String adUserName) {
        String sql = "select 1 from reguserinfo where username=?";
        List<Map<String, Object>> list = dbUtilitys.execSQL(sql, adUserName);
        if (list == null || list.size() == 0) {
            return false;
        }
        return true;
    }

    public boolean exists(String studentName, String studentNo) {
        String sql = "select 1 from reguserinfo where studentname=? and studentid=?";
        List<Map<String, Object>> list = dbUtilitys.execSQL(sql, studentName, studentNo);
        if (list == null || list.size() == 0) {
            return false;
        }
        return true;
    }

    public JSONObject getStudentInfo(String adUserName) {
        String sql = "select * from reguserinfo where username=? limit 1";
        List<Map<String, Object>> list = dbUtilitys.execSQL(sql, adUserName);
        if (list == null || list.size() == 0) {
            return new JSONObject();
        }
        return JSONObject.parseObject(JSONObject.toJSONString(list.get(0)));
    }

    public String getSex(String adUserName) {
        String sql = "select sexy from reguserinfo where username=? limit 1";
        List<Map<String, Object>> list = dbUtilitys.execSQL(sql, adUserName);
        if (list == null || list.size() == 0) {
            return "";
        }
        return list.get(0).get("sexy").toString();
    }
}
